package com.longshine.plc.ui;

import com.longshine.util.NumberUtil;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import org.jdesktop.layout.GroupLayout;


public class BerthControlPanel extends OwnPanel
{
  private ButtonGroup buttonGroup1;
  private ButtonGroup buttonGroup2;
  private ButtonGroup buttonGroup3;
  private ButtonGroup buttonGroup4;
  private ButtonGroup buttonGroup5;
  private ButtonGroup buttonGroup6;
  private ButtonGroup buttonGroup7;
  private JLabel jLabel21;
  private JLabel jLabel22;
  private JLabel jLabel23;
  private JLabel jLabel24;
  private JLabel jLabel25;
  private JLabel jLabel26;
  private JLabel jLabel27;
  private JLabel jLabel28;
  private JLabel jLabel29;
  private JLabel jLabel30;
  private JRadioButton jRadioButton29;
  private JRadioButton jRadioButton30;
  private JRadioButton jRadioButton31;
  private JRadioButton jRadioButton32;
  private JRadioButton jRadioButton33;
  private JRadioButton jRadioButton34;
  private JRadioButton jRadioButton35;
  private JRadioButton jRadioButton36;
  private JRadioButton jRadioButton37;
  private JRadioButton jRadioButton38;
  private JRadioButton jRadioButton39;
  private JRadioButton jRadioButton40;
  private JRadioButton jRadioButton41;
  private JRadioButton jRadioButton42;
  private JTextField jTextField10;
  private JTextField jTextField11;
  private JTextField jTextField9;

  public void init()
  {
    this.title = "车位控制台";
  }
  public void setHexData(String hexData) {
    this.jTextField11.setText(hexData);
    String binStr = NumberUtil.formatBinaryStr(NumberUtil.hex2Binary(hexData), 16);
    System.out.println("binStr=" +binStr);
    //10 00 00 00 00100000
    for (int i = 0; i < binStr.length(); i++) {
      boolean result = binStr.charAt(i) == '1';
      if (i == 0) {
        setPowerOn(result);
      }
      else if (i == 1) {
        setChargeBtn(result);
      }
      else if (i == 2) {
        setTransitBtn(result);
      }
      else if (i == 3) {
        setEmergencyStop(result);
      }
      else if (i == 4) {
        setPauseBtn(result);
      }
      else if (i == 12) {
        setBerthAlarmState(result);
      }
      else if (i == 13) {
        setCentreRoomAlarmState(result);
      }
    }
    this.jTextField10.setText(binStr);
    String readyStr = binStr.substring(8, 11);
    setReadyState((int)NumberUtil.binary2Decimal(readyStr));
  }
  public void setPowerOn(boolean result) {
    this.jRadioButton29.setSelected(result);
    this.jRadioButton30.setSelected(!result);
  }
  public void setChargeBtn(boolean result) {
    this.jRadioButton31.setSelected(result);
    this.jRadioButton32.setSelected(!result);
  }
  public void setTransitBtn(boolean result) {
    this.jRadioButton33.setSelected(result);
    this.jRadioButton34.setSelected(!result);
  }
  public void setEmergencyStop(boolean result) {
    this.jRadioButton35.setSelected(result);
    this.jRadioButton36.setSelected(!result);
  }
  public void setPauseBtn(boolean result) {
    this.jRadioButton37.setSelected(result);
    this.jRadioButton38.setSelected(!result);
  }
  public void setReadyState(int state) {
      System.out.println("state="+state);
      this.jTextField9.setText(state==0?"初始化":(state==1?"就位":(state==2?"工作中":"故障")));
  }

  public void setBerthAlarmState(boolean result) {
    this.jRadioButton39.setSelected(result);
    this.jRadioButton40.setSelected(!result);
  }
  public void setCentreRoomAlarmState(boolean result) {
    this.jRadioButton41.setSelected(result);
    this.jRadioButton42.setSelected(!result);
  }

  public BerthControlPanel()
  {
    initComponents();
  }

  private void initComponents()
  {
    this.buttonGroup1 = new ButtonGroup();
    this.buttonGroup2 = new ButtonGroup();
    this.buttonGroup3 = new ButtonGroup();
    this.buttonGroup4 = new ButtonGroup();
    this.buttonGroup5 = new ButtonGroup();
    this.buttonGroup6 = new ButtonGroup();
    this.buttonGroup7 = new ButtonGroup();
    this.jTextField10 = new JTextField();
    this.jRadioButton41 = new JRadioButton();
    this.jRadioButton37 = new JRadioButton();
    this.jLabel27 = new JLabel();
    this.jLabel24 = new JLabel();
    this.jLabel26 = new JLabel();
    this.jLabel25 = new JLabel();
    this.jLabel29 = new JLabel();
    this.jLabel28 = new JLabel();
    this.jRadioButton29 = new JRadioButton();
    this.jLabel22 = new JLabel();
    this.jLabel21 = new JLabel();
    this.jLabel23 = new JLabel();
    this.jRadioButton34 = new JRadioButton();
    this.jRadioButton32 = new JRadioButton();
    this.jRadioButton33 = new JRadioButton();
    this.jRadioButton35 = new JRadioButton();
    this.jRadioButton36 = new JRadioButton();
    this.jRadioButton39 = new JRadioButton();
    this.jRadioButton40 = new JRadioButton();
    this.jTextField9 = new JTextField();
    this.jRadioButton38 = new JRadioButton();
    this.jRadioButton42 = new JRadioButton();
    this.jRadioButton30 = new JRadioButton();
    this.jRadioButton31 = new JRadioButton();
    this.jLabel30 = new JLabel();
    this.jTextField11 = new JTextField();

    this.jTextField10.setEnabled(false);

    this.buttonGroup7.add(this.jRadioButton41);
    this.jRadioButton41.setText("1");
    this.jRadioButton41.setEnabled(false);

    this.buttonGroup6.add(this.jRadioButton37);
    this.jRadioButton37.setText("1");
    this.jRadioButton37.setEnabled(false);

    this.jLabel27.setText("暂停");

    this.jLabel24.setText("急停");

    this.jLabel26.setText("车位报警灯");

    this.jLabel25.setText("就位灯");

    this.jLabel29.setText("二进制");

    this.jLabel28.setText("中心机房报警灯");

    this.buttonGroup1.add(this.jRadioButton29);
    this.jRadioButton29.setText("1");
    this.jRadioButton29.setEnabled(false);

    this.jLabel22.setText("换电");

    this.jLabel21.setText("电源");

    this.jLabel23.setText("中转");

    this.buttonGroup3.add(this.jRadioButton34);
    this.jRadioButton34.setText("0");
    this.jRadioButton34.setEnabled(false);

    this.buttonGroup2.add(this.jRadioButton32);
    this.jRadioButton32.setText("0");
    this.jRadioButton32.setEnabled(false);

    this.buttonGroup3.add(this.jRadioButton33);
    this.jRadioButton33.setText("1");
    this.jRadioButton33.setEnabled(false);

    this.buttonGroup4.add(this.jRadioButton35);
    this.jRadioButton35.setText("1");
    this.jRadioButton35.setEnabled(false);

    this.buttonGroup4.add(this.jRadioButton36);
    this.jRadioButton36.setText("0");
    this.jRadioButton36.setEnabled(false);

    this.buttonGroup5.add(this.jRadioButton39);
    this.jRadioButton39.setText("1");
    this.jRadioButton39.setEnabled(false);

    this.buttonGroup5.add(this.jRadioButton40);
    this.jRadioButton40.setText("0");
    this.jRadioButton40.setEnabled(false);

    this.jTextField9.setEnabled(false);

    this.buttonGroup6.add(this.jRadioButton38);
    this.jRadioButton38.setText("0");
    this.jRadioButton38.setEnabled(false);

    this.buttonGroup7.add(this.jRadioButton42);
    this.jRadioButton42.setText("0");
    this.jRadioButton42.setEnabled(false);

    this.buttonGroup1.add(this.jRadioButton30);
    this.jRadioButton30.setText("0");
    this.jRadioButton30.setEnabled(false);

    this.buttonGroup2.add(this.jRadioButton31);
    this.jRadioButton31.setText("1");
    this.jRadioButton31.setEnabled(false);

    this.jLabel30.setText("十六进制");

    this.jTextField11.setEnabled(false);

    GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(1)
      .add(layout.createSequentialGroup()
      .add(27, 27, 27)
      .add(layout.createParallelGroup(2, false)
      .add(layout.createSequentialGroup()
      .add(layout.createParallelGroup(1)
      .add(this.jLabel21)
      .add(this.jLabel22)
      .add(this.jLabel23)
      .add(this.jLabel24)
      .add(this.jLabel25)
      .add(this.jLabel26)
      .add(this.jLabel27))
      .add(layout.createParallelGroup(1, false)
      .add(layout.createSequentialGroup()
      .add(83, 83, 83)
      .add(layout.createParallelGroup(2, false)
      .add(this.jRadioButton37)
      .add(this.jRadioButton41))
      .addPreferredGap(0, -1, 32767)
      .add(layout.createParallelGroup(1, false)
      .add(this.jRadioButton38)
      .add(this.jRadioButton42)))
      .add(layout.createSequentialGroup()
      .add(81, 81, 81)
      .add(layout.createParallelGroup(1, false)
      .add(this.jTextField9, -2, 206, -2)
      .add(layout.createSequentialGroup()
      .add(layout.createParallelGroup(1)
      .add(this.jRadioButton39)
      .add(this.jRadioButton29)
      .add(this.jRadioButton31)
      .add(this.jRadioButton33)
      .add(this.jRadioButton35))
      .addPreferredGap(0, -1, 32767)
      .add(layout.createParallelGroup(1, false)
      .add(this.jRadioButton36)
      .add(this.jRadioButton34)
      .add(this.jRadioButton32)
      .add(this.jRadioButton30)
      .add(this.jRadioButton40))))))
      .add(33, 33, 33))
      .add(layout.createSequentialGroup()
      .add(layout.createParallelGroup(1)
      .add(this.jLabel28)
      .add(this.jLabel29)
      .add(this.jLabel30))
      .addPreferredGap(0, -1, 32767)
      .add(layout.createParallelGroup(1, false)
      .add(this.jTextField10, -1, 202, 32767)
      .add(this.jTextField11))
      .add(35, 35, 35)))
      .addContainerGap(-1, 32767)));

    layout.setVerticalGroup(
      layout.createParallelGroup(1)
      .add(layout.createSequentialGroup()
      .add(21, 21, 21)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel21)
      .add(this.jRadioButton29)
      .add(this.jRadioButton30))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel22)
      .add(this.jRadioButton31)
      .add(this.jRadioButton32))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel23)
      .add(this.jRadioButton33)
      .add(this.jRadioButton34))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel24)
      .add(this.jRadioButton35)
      .add(this.jRadioButton36))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel27)
      .add(this.jRadioButton39)
      .add(this.jRadioButton40))
      .add(23, 23, 23)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel25)
      .add(this.jTextField9, -2, -1, -2))
      .add(32, 32, 32)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel26)
      .add(this.jRadioButton37)
      .add(this.jRadioButton38))
      .add(26, 26, 26)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel28)
      .add(this.jRadioButton41)
      .add(this.jRadioButton42))
      .add(27, 27, 27)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel29)
      .add(this.jTextField10, -2, -1, -2))
      .add(24, 24, 24)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel30)
      .add(this.jTextField11, -2, -1, -2))
      .addContainerGap(-1, 32767)));
  }
}